home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / MW MPW Binaries 1.1.1a2 / mwcPPC / MWCIncludes / fstream < prev    next >
Encoding:
Text File  |  1994-07-18  |  3.5 KB  |  151 lines  |  [TEXT/MMCC]

  1. // fstream standard header
  2. #ifndef _FSTREAM_
  3. #define _FSTREAM_
  4. #include <istream>
  5. #include <ostream>
  6.  
  7. #if __MWERKS__
  8. #pragma options align=mac68k
  9. #endif
  10.  
  11.         // class filebuf
  12. struct _Filet;
  13. class filebuf : public streambuf {
  14. public:
  15.     filebuf(_Filet *_F = 0)
  16.         {_Init(_F); }
  17.     filebuf(ios::_Uninitialized)
  18.         : streambuf(ios::_Noinit) {}
  19.     virtual ~filebuf();
  20.     _Bool is_open() const
  21.         {return ((_File != 0)); }
  22.     filebuf *open(const char *, ios::openmode);
  23.     filebuf *close();
  24. #if _HAS_ENUM_OVERLOADING
  25.     filebuf *open(const char *_N, ios::open_mode _M)
  26.         {return (open(_N, (openmode)_M)); }
  27. #endif
  28. protected:
  29.     virtual int overflow(int = EOF);
  30.     virtual int pbackfail(int = EOF);
  31.     virtual int underflow();
  32.     virtual int uflow();
  33.     virtual int xsgetn(char *, int);
  34.     virtual int xsputn(const char *, int);
  35.     virtual streampos seekoff(streamoff, ios::seekdir,
  36.         ios::openmode = (ios::openmode)(ios::in | ios::out));
  37.     virtual streampos seekpos(streampos,
  38.         ios::openmode = (ios::openmode)(ios::in | ios::out));
  39.     virtual streambuf *setbuf(char *, int);
  40.     virtual int sync();
  41.     _Filet *_Init(_Filet * = 0);
  42. private:
  43.     _Bool _Closef;
  44.     _Filet *_File;
  45.     };
  46.         // class ifstream
  47. class ifstream : public istream {
  48. public:
  49.     ifstream()
  50.         : ios(&_Fb), istream(&_Fb) {}
  51.     ifstream(const char *_S, openmode _M = in)
  52.         : ios(&_Fb), istream(&_Fb) {_Fb.open(_S, _M); }
  53.     virtual ~ifstream();
  54.     filebuf *rdbuf() const
  55.         {return ((filebuf *)&_Fb); }
  56.     _Bool is_open() const
  57.         {return (_Fb.is_open()); }
  58.     void open(const char *_S, openmode _M = in)
  59.         {if (_Fb.open(_S, _M) == 0)
  60.              setstate(failbit); }
  61.     void close()
  62.         {if (_Fb.close() == 0)
  63.              setstate(failbit); }
  64. #if _HAS_ENUM_OVERLOADING
  65.     void open(const char *_S, open_mode _M = in)
  66.         {open(_S, (openmode)_M; }
  67. #endif
  68. private:
  69.     filebuf _Fb;
  70.     };
  71.         // class ofstream
  72. class ofstream : public ostream {
  73. public:
  74.     ofstream()
  75.         : ios(&_Fb), ostream(&_Fb) {}
  76.     ofstream(const char *_S, openmode _M = out | trunc)
  77.         : ios(&_Fb), ostream(&_Fb) {_Fb.open(_S, _M); }
  78.     virtual ~ofstream();
  79.     filebuf *rdbuf() const
  80.         {return ((filebuf *)&_Fb); }
  81.     _Bool is_open() const
  82.         {return (_Fb.is_open()); }
  83.     void open(const char *_S, openmode _M = out | trunc)
  84.         {if (_Fb.open(_S, _M) == 0)
  85.              setstate(failbit); }
  86.     void close()
  87.         {if (_Fb.close() == 0)
  88.              setstate(failbit); }
  89. #if _HAS_ENUM_OVERLOADING
  90.     void open(const char *_S, open_mode _M = out | trunc)
  91.         {open(_S, (openmode)_M; }
  92. #endif
  93. private:
  94.     filebuf _Fb;
  95.     };
  96.         // class stdiobuf
  97. class stdiobuf : public filebuf {
  98. public:
  99.     stdiobuf(_Filet *_F = 0)
  100.         : filebuf(_F), _Is_buffered(0) {}
  101.     virtual ~stdiobuf();
  102.     _Bool buffered() const
  103.         {return (_Is_buffered); }
  104.     void buffered(_Bool _F)
  105.         {_Is_buffered = _F; }
  106. private:
  107.     _Bool _Is_buffered;
  108.     };
  109.         // class istdiostream
  110. class istdiostream : public istream {
  111. public:
  112.     istdiostream(_Filet *_F = 0)
  113.         : ios(&_Fb), istream(&_Fb), _Fb(_F) {}
  114.     virtual ~istdiostream();
  115.     stdiobuf *rdbuf() const
  116.         {return ((stdiobuf *)&_Fb); }
  117.     _Bool buffered() const
  118.         {return (_Fb.buffered()); }
  119.     void buffered(_Bool _F)
  120.         {_Fb.buffered(_F); }
  121. private:
  122.     stdiobuf _Fb;
  123.     };
  124.         // class ostdiostream
  125. class ostdiostream : public ostream {
  126. public:
  127.     ostdiostream(_Filet *_F = 0)
  128.         : ios(&_Fb), ostream(&_Fb), _Fb(_F) {}
  129.     virtual ~ostdiostream();
  130.     stdiobuf *rdbuf() const
  131.         {return ((stdiobuf *)&_Fb); }
  132.     _Bool buffered() const
  133.         {return (_Fb.buffered()); }
  134.     void buffered(_Bool _F)
  135.         {_Fb.buffered(_F); }
  136. private:
  137.     stdiobuf _Fb;
  138.     };
  139.  
  140. #if __MWERKS__
  141. #pragma options align=reset
  142. #endif
  143.  
  144. #endif
  145.  
  146. /*
  147.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  148.  * Consult your license regarding permissions and restrictions.
  149.  */
  150.  
  151.